import sys
sys.path.append('..\\..')
from Djoser import *


class MyApplication(DjApplication):
	def layout(self, window):
		window.frame(V, layout='fill,expand')
		window.frame(H, layout='fill,expand', borderwidth=2,borderstyle='raised')
		window.label('Text:')
		self.myinput = window.input('text', layout='fillx,expand')
		window.endframe()
		
		window.frame(H)
		window.button('read',self.readFromField )
		window.button('timeout',self.testTimeout )
		window.button('cancel',self.testCancelTimeout )
		
		window.button('getclipboard', lambda:self.echo(self.get_clipboard()) )
		window.button('setclipboard', lambda:self.set_clipboard('hello') )
		window.button('beep',lambda:self.beep() )
		window.button('quit',lambda:self.quit() )
		window.endframe()
		window.endframe()
		
		window.add_all()
	
	def menubar(self, window):
		# Actually, don't use something this expansive for just a shortcut.
		#self.set_onkey_callback({'Ctrl+O':self.open })
		window.set_shortcut_key('Ctrl+O',self.open)
		return DjMenu(window,
			['File',
				'&New',None,
				'Open Document|Ctrl+O|OPEN', self.open,
				'Beep', self.beep
			]
		)
	
	def echo(self, s):
		print s
	
	def readFromField(self):
		print self.myinput.text
	
	def open(self): print 'open'
		
	def testTimeout(self):
		def doSomething(): print 'It happened!'
		self._id = self.setTimeout(1000, doSomething)
		
	def testCancelTimeout(self):
		if hasattr(self, '_id'):
			self.cancelTimeout(self._id)
		
m = MyApplication()
m.run()
			
			
